<template>
  <div class="nav-all">
    <div class="nav-con">
      <span>轮播样式:</span>
      <div class="nav-con-style">
        <div
          v-for="(item,idx) in swiperStyle"
          style="margin-left:10px;display:inline-block"
          :key="idx"
        >
          <img
            :class="styleIdx === idx ? 'img-active' : '' "
            :src="item.imgurl"
            @click="checkSty(idx, item.name)"
            alt
          />
        </div>
      </div>
    </div>
    <div class="nav-con">
      <span>斑点提示:</span>
      <div class="nav-spot">
        <div
          v-for="(child, pointIdx) in poinitSty"
          :key="pointIdx"
          style="margin-left:10px;display:inline-block"
        >
          <img
            :src="child.imgurl"
            :class="myswiper.poinitIdx === pointIdx ? 'img-active' : '' "
            @click="poinitStyTrue(pointIdx)"
          />
        </div>
      </div>
    </div>
    <div class="nav-con">
      <span>自动播放:</span>
      <div class="nav-spot">
        <el-radio-group v-model="myswiper.autopaly">
          <el-radio :label="1">开</el-radio>
          <el-radio :label="0">关</el-radio>
        </el-radio-group>
      </div>
    </div>
    <div class="nav-con nav-con-left">
      <span>播放间隔:</span>
      <input type="text" v-model="myswiper.delay" class="mainKey" />
      <span style="margin-left:8px">毫秒</span>
    </div>
    <div class="nav-con nav-con-img" style="margin-top:10px;height: auto;">
      <span>上传图片:</span>
      <div class="upImg-list">
        <div
          class="upImg-data"
          v-for="(imgs, idx) in myswiper.data"
          :key="idx"
          @click="chooseImg(idx)"
        >
          <img class="upImg-data-img" :src="imgs.backgroungImage" alt />
          <img src="@/assets/config_images/del.png" class="del-Img" @click.stop="delImg(idx)" alt="">
        </div>
        <img class="upimg" @click="addImg" src="@/assets/config_images/addimg.png" alt />
      </div>
    </div>
    <div class="nav-con">
      <span>跳转:</span>
      <input type="text" v-model="myswiper.mainKey" class="mainKey" />
      <div class="add-tag">
        <span>选择跳转</span>
      </div>
    </div>
    <UploadImages @closeModel="closeModel" :dialogVisible="showImg"></UploadImages>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import UploadImages from "@/components/UploadImages/UploadImages";
export default {
  components: {
    UploadImages
  },
  computed: {
    ...mapGetters(["myswiper", "ImgUrl"])
  },
  data() {
    return {
      showImg: false,
      imgIdx: 0,
      styleIdx: 0,
      swiperStyle: [
        {
          imgurl: require("../../../assets/config_images/swiper1.gif"),
          name: "slide"
        },
        {
          imgurl: require("../../../assets/config_images/swiper2.gif"),
          name: "fade"
        }
      ],
      poinitSty: [
        {
          imgurl: require("../../../assets/config_images/dian_1.png")
        },
        {
          imgurl: require("../../../assets/config_images/dian_2.png")
        }
      ]
    };
  },
  watch: {
    myswiper: {
      handler(old, newVal) {
        this.$store.dispatch("apply/PageJSONUpData");
        // 更新父组件中的PageJSON
        this.$emit("updataNowPageJSON", newVal);
        this.$store.commit("myswiper/SET_SWIPEROBJ", newVal)
      },
      deep: true
    },
    ImgUrl: function(val, oldval) {
      this.myswiper.data[this.imgIdx].backgroungImage = val;
    }
  },
  methods: {
    checkSty(idx, name) {
      this.styleIdx = idx;
      this.myswiper.styleName = name;
    },
    poinitStyTrue(idx) {
      this.myswiper.poinitIdx = idx;
    },
    closeModel() {
      this.showImg = false;
    },
    chooseImg(idx) {
      this.showImg = true;
      this.imgIdx = idx;
    },
    // 添加图片
    addImg() {
      this.showImg = true;
      const obj = {
        backgroungImage: this.ImgUrl,
        gourl: ""
      };
      this.myswiper.data.push(obj);
    },
    // 删除图片
    delImg(idx) {
      this.myswiper.data.splice(idx, 1);
    }
  }
};
</script>
<style lang="scss" scoped>
@import "./diyset.scss";
.nav-all {
  width: 100%;
  height: 100%;
  padding-top: 20px;
  display: flex;
  flex-direction: column;
  .nav-con {
    @include flexCon(278px, 50px, center, flex-start, 64px);
    position: relative;
    input {
      @include wd(225px, 30px);
      background: rgba(255, 255, 255, 1);
      border-radius: 3px;
      font-size: 14px;
      padding-left: 8px;
      border: 1px solid rgba(223, 223, 223, 1);
    }
  }
  .nav-con {
    @include flexCon(290px, 50px, center, space-between, 64px);
    position: relative;
    margin-top: 20px;
    .nav-con-style {
      width: 214px;
      .img-active {
        border: 1px solid #1f75f6;
      }
      img {
        width: 76px;
        height: 60px;
      }
    }
    input {
      @include wd(225px, 30px);
      background: rgba(255, 255, 255, 1);
      border-radius: 3px;
      font-size: 14px;
      padding-left: 8px;
      border: 1px solid rgba(223, 223, 223, 1);
    }
    .nav-spot {
      width: 214px;
      margin-left: 15px;
      .img-active {
        border: 1px solid #1f75f6;
      }
    }
    .mainKey {
      width: 80px;
      height: 30px;
      border-radius: 2px;
      margin-left: 20px;
      border: 1px solid rgba(224, 225, 232, 1);
    }
    .add-tag {
      @include wd(auto, 30px);
      border-radius: 2px;
      font-size: 14px;
      text-align: center;
      line-height: 30px;
      padding: 0 10px;
      padding-left: 20px;
      border: 1px solid rgba(224, 225, 232, 1);
      cursor: pointer;
    }
  }
  .nav-con-img {
    justify-content: flex-start;

    .upImg-list {
      display: flex;
      flex-wrap: wrap;
      margin: 10px 0 0 20px;
      .upImg-data {
        width: 40px;
        height: 40px;
        position: relative;
        background: rgba(162, 162, 162, 1);
        border-radius: 3px;
        margin: 10px 0 0 10px;
        .upImg-data-img {
          width: 100%;
          height: 100%;
        }
        .del-Img {
          position: absolute;
          right: 0;
          top: 0;
        }
      }
    }
    .upimg {
      width: 40px;
      height: 40px;
      margin: 10px 0 0 10px;
    }
  }
  .nav-con-left {
    justify-content: flex-start;
    input {
      margin-left: 20px;
    }
  }
}
</style>
